package com.hichina.client;

import com.hichina.exception.HiChinaException;
import org.apache.commons.lang.StringUtils;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by IntelliJ IDEA.
 * User: zigang.wang
 * Date: 12-5-28
 * Time: 上午10:21
 * To change this template use File | Settings | File Templates.
 */
public class Department {
    private String id;
    private String name;
    private String parent_id;
    private int accountNum;
    private String domain_id;

    public Department() {
    }

    public Department(JSONObject jsonObject) throws HiChinaException {
        try {
            this.id = jsonObject.getString("id");
            this.accountNum = jsonObject.getInt("accountNum");
            this.name = jsonObject.getString("name");
            this.parent_id = jsonObject.getString("parent_id");
            if(jsonObject.has("parentId")){
                this.parent_id = jsonObject.getString("parentId");
            }
            this.domain_id = jsonObject.getString("domain_id");
        } catch (JSONException e) {
            throw new HiChinaException(jsonObject.toString() +", can't convert to Department");
        }
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getParent_id() {
        return parent_id;
    }

    public void setParent_id(String parent_id) {
        this.parent_id = parent_id;
    }

    public int getAccountNum() {
        return accountNum;
    }

    public void setAccountNum(int accountNum) {
        this.accountNum = accountNum;
    }

    public String getDomain_id() {
        return domain_id;
    }

    public void setDomain_id(String domain_id) {
        this.domain_id = domain_id;
    }

    @Override
    public String toString() {
        return "Department{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", parent_id='" + parent_id + '\'' +
                ", accountNum=" + accountNum +
                ", domain_id='" + domain_id + '\'' +
                '}';
    }
}
